package com.teemor.common.datasource.controller.es;

import com.teemor.common.bean.datasource.input.QryArticlesIPo;
import com.teemor.common.bean.datasource.output.QryArticlesOPo;
import com.teemor.common.bean.model.EsOutputModel;
import com.teemor.common.bean.model.EsQueryModel;
import com.teemor.common.datasource.api.es.IArticleSearch;
import com.teemor.common.datasource.service.IArticleSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author zhoulk
 * @date: 2019/12/14
 */
@RestController
public class ArticleSearchController implements IArticleSearch {

    @Autowired
    IArticleSearchService iArticleSearchService;

    @Override
    public EsOutputModel<QryArticlesOPo> searchArticles(@RequestBody EsQueryModel<QryArticlesIPo> inParam) {
        return iArticleSearchService.searchArticles(inParam);
    }

    @Override
    public Map<String, List<QryArticlesOPo>> test() {
        Map<String, List<QryArticlesOPo>> map = new HashMap<>();
        List<QryArticlesOPo> list = new ArrayList<QryArticlesOPo>() {{
            QryArticlesOPo oPo = new QryArticlesOPo();
            oPo.setAtcId(1);
            oPo.setCover("dsfasfsdfasd");
            oPo.setAtcState(1);
            oPo.setCreateTime(new Date());
            add(oPo);
            oPo = new QryArticlesOPo();
            oPo.setAtcId(1);
            oPo.setCover("dsfasfsdfasd");
            oPo.setAtcState(1);
            oPo.setCreateTime(new Date());
            add(oPo);
        }};
        map.put("data", list);
        return map;
    }
}
